package csel.model;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.Test; 


public class EntityTester extends TestCase
{
	Entity e;

	public static void main(String args[]) 
	{ 
		junit.textui.TestRunner.run(MapTester.class); 
	} 
	@Test
	public void testMoveOne()
	{
		Model m = new Model();
		GameFactory.newGame(new Summoner(), "Bryan", m);
		e = m.getPlayerEntity();
		
		Tile myTile = e.getLocation();
		
		System.out.println(myTile);
		
		Location myLocation = myTile.getLocation();
		
		System.out.println(myLocation);
		
		boolean moved;
		
		e.setTicksSinceLastMove(e.getSpeed());
		moved = e.moveOne(Direction.EAST);
		
		System.out.println(moved);
		
		Assert.assertEquals(myLocation.getX()+1, e.getLocation().getLocation().getX());
		Assert.assertEquals(myLocation.getY(), e.getLocation().getLocation().getY());
		
		e.setTicksSinceLastMove(e.getSpeed());
		moved = e.moveOne(Direction.WEST);
		System.out.println(moved);
		Assert.assertTrue(moved);
		Assert.assertEquals(myLocation.getX(), e.getLocation().getLocation().getX());
		Assert.assertEquals(myLocation.getY(), e.getLocation().getLocation().getY());
		
		e.setTicksSinceLastMove(e.getSpeed());
		moved = e.moveOne(Direction.NORTH);
		
		Assert.assertTrue(moved);
		Assert.assertEquals(myLocation.getX(), e.getLocation().getLocation().getX());
		Assert.assertEquals(myLocation.getY()+1, e.getLocation().getLocation().getY());
		
		e.setTicksSinceLastMove(e.getSpeed());
		moved = e.moveOne(Direction.SOUTH);
		
		Assert.assertTrue(moved);
		Assert.assertEquals(myLocation.getX(), e.getLocation().getLocation().getX());
		Assert.assertEquals(myLocation.getY(), e.getLocation().getLocation().getY());
		
		e.setTicksSinceLastMove(e.getSpeed());
		moved = e.moveOne(Direction.NORTHEAST);
		
		Assert.assertTrue(moved);
		Assert.assertEquals(myLocation.getX()+1, e.getLocation().getLocation().getX());
		Assert.assertEquals(myLocation.getY()+1, e.getLocation().getLocation().getY());
		
		e.setTicksSinceLastMove(e.getSpeed());
		moved = e.moveOne(Direction.SOUTHWEST);
		
		Assert.assertTrue(moved);
		Assert.assertEquals(myLocation.getX(), e.getLocation().getLocation().getX());
		Assert.assertEquals(myLocation.getY(), e.getLocation().getLocation().getY());
		
		e.setTicksSinceLastMove(e.getSpeed());
		moved = e.moveOne(Direction.NORTHWEST);
		
		Assert.assertTrue(moved);
		Assert.assertEquals(myLocation.getX()-1, e.getLocation().getLocation().getX());
		Assert.assertEquals(myLocation.getY()+1, e.getLocation().getLocation().getY());
		
		e.setTicksSinceLastMove(e.getSpeed());
		moved = e.moveOne(Direction.SOUTHEAST);
		
		Assert.assertTrue(moved);
		Assert.assertEquals(myLocation.getX(), e.getLocation().getLocation().getX());
		Assert.assertEquals(myLocation.getY(), e.getLocation().getLocation().getY());
	}
	@Test
	public void testMove_Direction()
	{
		Model m = new Model();
		GameFactory.newGame(new Summoner(), "Bryan", m);
		e = m.getPlayerEntity();
		
		Tile myTile = e.getLocation();
		
		System.out.println(myTile);
		
		Location myLocation = myTile.getLocation();
		
		int x = myLocation.getX();
		int y = myLocation.getY();
		
		e.setTicksSinceLastMove(e.getSpeed());
		int timePerMove = e.getSpeed() * 100;
		
		e.move(Direction.SOUTH);
		y--;
		Assert.assertEquals(x, e.getLocation().getLocation().getX());
		Assert.assertEquals(y, e.getLocation().getLocation().getY());
		e.stop();
		e.move(Direction.SOUTH);
		e.stop();
		e.move(Direction.EAST);
		e.stop();
		Assert.assertEquals(x, e.getLocation().getLocation().getX());
		Assert.assertEquals(y, e.getLocation().getLocation().getY());
		e.move(Direction.SOUTH);
		e.move(Direction.SOUTH);
		e.move(Direction.SOUTH);
		e.move(Direction.SOUTH);
		e.move(Direction.SOUTH);
		e.move(Direction.SOUTH);
		e.move(Direction.SOUTH);
		e.move(Direction.SOUTH);
		e.move(Direction.SOUTH);
		e.move(Direction.SOUTH);
		y--;
		try
		{
			Thread.sleep(timePerMove);
		} catch (InterruptedException e1)
		{
			e1.printStackTrace();
		}
		Assert.assertEquals(x, e.getLocation().getLocation().getX());
		Assert.assertEquals(y, e.getLocation().getLocation().getY());
		e.move(Direction.WEST);
		Assert.assertEquals(x, e.getLocation().getLocation().getX());
		Assert.assertEquals(y, e.getLocation().getLocation().getY());
		x--;
		try
		{
			Thread.sleep(timePerMove);
		} catch (InterruptedException e1)
		{
			e1.printStackTrace();
		}
		Assert.assertEquals(x, e.getLocation().getLocation().getX());
		Assert.assertEquals(y, e.getLocation().getLocation().getY());
		try
		{
			Thread.sleep(timePerMove);
		} catch (InterruptedException e1)
		{
			e1.printStackTrace();
		}
		Assert.assertEquals(x, e.getLocation().getLocation().getX());
		Assert.assertEquals(y, e.getLocation().getLocation().getY());
	}
}
